#include<bits/stdc++.h>
using namespace std;
int n,ans;
int a[2*100000+5],f[2*100000+5];
void dfs(int step,int cnt,int last1,int last2){
    if(step==n+1){
        ans=max(ans,cnt);
        return;
    }
    f[step]=1;
    if(last1==-1){
        dfs(step+1,cnt,step,last2);
    }else {
        if(a[last1]==a[step]){
            dfs(step+1,cnt+a[step],step,last2);
        }
        else dfs(step+1,cnt,step,last2);
    }

    f[step]=0;
    if(last2==-1){
        dfs(step+1,cnt,last1,step);
    }else {
        if(a[last2]==a[step]){
            dfs(step+1,cnt+a[step],last1,step);
        }
        else dfs(step+1,cnt,last1,step);
    }
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;cin >> T;while(T--){
        cin >> n;
        for(int i=1;i<=n;i++)cin>>a[i];
        ans = 0;dfs(1,0,-1,-1);cout << ans << '\n';
    }return 0;
}
